package com.example.helloworld.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.helloworld.R;
import com.example.helloworld.persistence.IconTextItem;

public class IconTextView extends LinearLayout {

	private ImageView icon;
	private TextView text01;
	private TextView text02;
	private TextView text03;
	
	public IconTextView(Context context, IconTextItem item) {
		super(context);
		
		LayoutInflater inflater =	(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.listitem, this, true);
		
		icon =		(ImageView)findViewById(R.id.iconItem);
		icon.setImageDrawable(item.getIcon());
		
		text01 =	(TextView)findViewById(R.id.dataItem01);
		text01.setText(item.getData(0));
		
		text02 =	(TextView)findViewById(R.id.dataItem02);
		text02.setText(item.getData(1));
		
		text03 =	(TextView)findViewById(R.id.dataItem03);
		text03.setText(item.getData(2));
	}
	
	public void setText(int index, String data) {
		if (index == 0) {
			text01.setText(data);
		} else
		if (index == 1) {
			text02.setText(data);
		} else
		if (index == 2) {
			text03.setText(data);
		} else {
			throw new IllegalArgumentException();
		}
	}

	public void setIcon(Drawable icon) {
		this.icon.setImageDrawable(icon);
	}
}
